﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     RequestInfo业务接口的实现
    /// 作者：     lwl
    /// 日期：     2011/10/14
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class RequestInfoSqlMapDao : BaseSqlMapDao, IRequestInfoDao
    {
        private static RequestInfoSqlMapDao instance = null;
        private static object syncRoot = new object();

        private RequestInfoSqlMapDao()
        {
            //
            // TODO: 此处添加RequestInfoSqlMapDao的构造函数
            //
        }
        public static IRequestInfoDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new RequestInfoSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectRequestInfoByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<RequestInfo> GetList()
        {
            try
            {
                return ExecuteQueryForList<RequestInfo>("SelectRequestInfo", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<RequestInfo> SelectListOfConditions(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<RequestInfo>("SelectListOfConditions", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="RequestID"></param>
        /// <returns></returns>
        public RequestInfo GetDetail(System.String requestid)
        {
            try
            {
                RequestInfo request= ExecuteQueryForObject<RequestInfo>("SelectRequestInfo", requestid) as RequestInfo;
                Handler.RequestHandler handler = new Handler.RequestHandler();
                return handler.GetFullRequest(request);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="requestinfo"></param>
        /// <returns></returns>
        public object Add(RequestInfo requestinfo)
        {
            //int id = GetId("RequestInfo");
            //requestinfo.RequestID = id;

            try
            {
                return ExecuteInsert("InsertRequestInfo", requestinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="requestinfo"></param>
        /// <returns></returns>
        public int Update(RequestInfo requestinfo)
        {
            try
            {
                return ExecuteUpdate("UpdateRequestInfo", requestinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="RequestID"></param>
        /// <returns></returns>
        public int Delete(System.String requestid)
        {
            try
            {
                return ExecuteDelete("DeleteRequestInfo", requestid);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="requestinfo"></param>
        /// <returns></returns>
        public int Delete(RequestInfo requestinfo)
        {
            try
            {
                return ExecuteDelete("DeleteRequestInfo", requestinfo.RequestID);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<RequestInfo> GetRequestInfoListPage(object objParameters)
        {
            try
            {
                Handler.RequestHandler handler = new Handler.RequestHandler();
                ExecuteWithRowDelegate("GetRequestInfoPage", objParameters, new IBatisNet.DataMapper.RowDelegate(handler.GetFullList));
                return handler.requestlist;
                //return ExecuteQueryForList<RequestInfo>("GetRequestInfoPage", objParameters);
            }
            catch
            {

                throw;
            }
        }
    }
}
